using System;
using FireStarterModeller.BO;
using Habanero.Testability;

namespace FireStarterModeller.Test.BO
{
    public class TestUtilsUIField
    {
        private static BOTestFactory<UIField> _factory = GetFactory();

        public static BOTestFactory<UIField> GetFactory()
        {
            return BOTestFactoryRegistry.Instance.Resolve<UIField>();
        }

        private static int OrdinalPosition = 1;
        /// <summary>
        /// Creates a new saved UIField with a random value assigned to every property
        /// </summary>
        public static UIField CreateSavedUIField()
        {
            UIField uIField = CreateUnsavedValidUIField();
            uIField.Save();
            return uIField;
        }

        /// <summary>
        /// Creates a new unsaved UIField with a random value assigned to every property
        /// </summary>
        public static UIField CreateUnsavedValidUIField()
        {
            UIField uIField = new UIField();
            uIField.LabelText = TestUtilsShared.GetRandomString();
            uIField.PropertyName = TestUtilsShared.GetRandomString();
            uIField.UIControlTypeID = TestUtilsUIControlType.CreateSavedUIControlType().UIControlTypeID;
            uIField.UIControlMapperTypeID =
                TestUtilsUIControlMapperType.CreateSavedUIControlMapperType().UIControlMapperTypeID;
            uIField.Editable = TestUtilsShared.GetRandomBoolean();
            uIField.ToolTipText = TestUtilsShared.GetRandomString();
            uIField.Generated = TestUtilsShared.GetRandomBoolean();
            uIField.UIColumnLayoutID = TestUtilsUIColumnLayout.CreateSavedUIColumnLayout().UIColumnLayoutID;
            uIField.OrdinalPosition = ++OrdinalPosition;
            return uIField;
        }

        /// <summary>
        /// Creates a new unsaved UIField where all properties are null, except ID properties
        /// and those with default values.  If there are compulsory properties without
        /// defaults, saving the object will throw an exception.
        /// </summary>
        public static UIField CreateUnsavedDefaultUIField()
        {
            UIField uIField = new UIField();
            return uIField;
        }
    }
}